package com.manner.groupon.controller.admin;

import com.manner.groupon.common.BaseResponse;
import com.manner.groupon.common.ResultUtils;
import com.manner.groupon.model.entity.SysDict;
import com.manner.groupon.service.sys.SysDictService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/dict")
@RequiredArgsConstructor
    
public class SysDictController {

    @Resource
    private SysDictService sysDictService;

    @GetMapping
    public BaseResponse<List<SysDict>> list() {
        List<SysDict> list = sysDictService.list();
        return ResultUtils.success(list);
    }

    @PostMapping
    public BaseResponse<String> save(@RequestBody SysDict sysDict) {
        sysDictService.save(sysDict);
        return ResultUtils.success("保存成功");
    }

    @GetMapping("/{id}")
    public BaseResponse<SysDict> queryById(@PathVariable Long id) {
        SysDict dict = sysDictService.getById(id);
        return ResultUtils.success(dict);
    }

    @PutMapping
    public BaseResponse<String> update(@RequestBody SysDict sysDict) {
        sysDictService.updateById(sysDict);
        return ResultUtils.success("修改成功");
    }

}
